/**
 * Created by Yun on 2016-04-01.
 */

import { subscribe } from './pubsub';

export default function (target, property, descriptor){
  return class extends target {
    _subscribes = [];
    componentWillUnmount() {
      super.componentWillUnmount && super.componentWillUnmount();
      for (const k in this._subscribes) {
        this._subscribes[k]();
      }
    }
    subscribe(name, func) {
      this._subscribes.push(subscribe(name, func || (() => this.forceUpdate())));
    }
  }
}
